package com.spera.shopoa.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.spring.security.web.filter.SpringMVCInterceptor;

public class ShopOaInterceptor implements HandlerInterceptor{
	static Logger logger = Logger.getLogger(SpringMVCInterceptor.class
			.getName());
	
	@SuppressWarnings("unchecked")
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		/*Map<String,Object> jsonMap = */ShopOaSessionUtil.checkOaSession(request);
		System.out.println("---------->"+request.getContextPath());
		return true;
//		if(request.getSession() != null &&request.getSession().getAttribute(ShopOaSessionUtil.SHOPOA_USER) !=null){
////			Map<String,Object> user_info = (Map<String,Object>)request.getSession().getAttribute(ShopOaSessionUtil.SHOPOA_USER);
////			List<Map<String,Object>> user_role = (List<Map<String,Object>>)request.getSession().getAttribute(ShopOaSessionUtil.SHOPOA_ROLE);
//			List<Map<String,Object>> user_priv = (List<Map<String,Object>>)request.getSession().getAttribute(ShopOaSessionUtil.SHOPOA_MENU);
//			System.out.println("---------->"+request.getContextPath());
//			CharSequence url = request.getRequestURI();
//			if(ApplicationUtils.isNotNull(user_priv)){
//				String menuUrl = "";
//				boolean isIn = false;
//				for(Map<String,Object> m:user_priv){
//					menuUrl = (String)m.get("func_url");
//					if(menuUrl.contains(url)){
//						isIn = true;
//					}
//				}
//				if(isIn){
//					//response.sendRedirect(url+"");
//					return true;
//				}else{
//					response.sendRedirect(request.getContextPath() + "/SperaOther/page/404");
//					return false;
//				}
//			}else{
//				response.sendRedirect(request.getContextPath() + "/SperaOther/page/404");
//				return false;
//			}
//		}else{
//			response.sendRedirect(request.getContextPath() + "/SperaOther/page/404");
//			return false;
//		}
	}

	@Override
	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response,
			Object arg2, ModelAndView arg3) throws Exception {

	}
}
